package registnet.base;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Iterator;

public class Form5 extends AbstractForm5 {

	public Form5(String studentNumber, int semester, int year){
		this.studentNumber = studentNumber;
		this.year = year;
		this.semester = semester;
	}
	
	public int getTotalUnits(){
		int totalUnits = 0;
		HashMap<String, CourseTaken> courses = this.getAllCourses();
		Iterator<String> iter = courses.keySet().iterator();
		while(iter.hasNext()){
			CourseTaken course = this.courses.get(iter.next());
			totalUnits += course.getUnit();
		}
		return totalUnits;
	}
	
	public double getGWA(){
		double GWA = 0;
		int totalUnits = 0;
		HashMap<String, CourseTaken> courses = this.getAllCourses();
		Iterator<String> iter = courses.keySet().iterator();
		DecimalFormat df = new DecimalFormat();
		df.setMinimumFractionDigits(4);
		while(iter.hasNext()){
			CourseTaken course = this.courses.get(iter.next());
			if (new Double(course.getReExam()) != new Double(0)){
				GWA += course.getGrade() * course.getUnit();
				totalUnits += course.getUnit();
			}
			else{
				GWA += course.getReExam() * course.getUnit();
				totalUnits += course.getUnit();
			}
			
		}
		return Double.parseDouble(df.format(GWA/totalUnits));
	}

}
